package com.api.workflow.web;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.DetailTable;
import weaver.soa.workflow.request.RequestInfo;

/*
 *采购订单创建校验
 *
 */
public class PurchaseOrderVerificationAction extends BaseBean implements Action {


    @Override
    public String execute(RequestInfo requestInfo) {
        try {
            //获得流程id
            String workflowid = requestInfo.getWorkflowid();
            //获取表id
            String requestid = requestInfo.getRequestid();
            writeLog("PurchaseOrderVerificationAction-----start----------------------" + requestid);
            RecordSet rs = new RecordSet();
            rs.execute("select tablename from workflow_base a,workflow_bill b where a.formid=b.id and a.id=" + workflowid);
            rs.next();
            //获取主表名
            DetailTable[] detailTable = requestInfo.getDetailTableInfo().getDetailTable();
            //获取主表名
            String maintable = Util.null2String(rs.getString("tablename"));

            //根据表id和主表名查找主表的相关信息
            rs.executeQuery("select * from " + maintable + " where requestid=?", new Object[]{requestid});
            rs.next();
            String hcbs = Util.null2String(rs.getString("hcbs"));//回传接口
            String sfkjht = Util.null2String(rs.getString("sfkjht"));//是否框架合同
            writeLog("hcbshcbshcbshcbshcbs" + hcbs);
            if (sfkjht.equals("0")) {
                return Action.SUCCESS;
            } else {
                if (hcbs.trim().equals("1")) {
                    return Action.SUCCESS;
                } else {
                    requestInfo.getRequestManager().setMessagecontent("子流程暂未归档，请您耐心等待子流程归档之后，再进行提交相关流程!");
                    return Action.FAILURE_AND_CONTINUE;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessagecontent("接口出错,请联系管理员!" + e.getMessage());
        }
        return Action.SUCCESS;

    }

}
